// get_arg.h
//

#if !defined(GETARG_H)
#define GETARG_H

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <string>
//#include <iosfwd>
#include <sstream>
#include <iostream>
#include <fstream>

// adhoc solution to output to two streams at once
struct dual_streams
{
	dual_streams(std::ostream& os1_, std::ostream& os2_)
		: os1(os1_), os2(os2_){}
	dual_streams(const dual_streams& ds)
		: os1(ds.os1), os2(ds.os2){}
	std::ostringstream 		strm_;
	std::ostringstream&		strm() {return strm_;};
	std::ostream&			os1;
	std::ostream&			os2;
	~dual_streams()
	{
		if (strm_.str().length())
		{
			os1 		<< strm_.str();
			os2 		<< strm_.str();
		}
	}
};

class t_program_args
{
public:

	// database login string
	std::string		db_login;
	
	// batch
	std::string		error_table;
	std::string		job_category;
	std::string		output_table;
	std::string		map_table;

	// for error / progress messages etc.
	// N.B.
	//		CERR		defaults to cerr
	//		MISSING_SEQ defaults to null
	//      BLAST_LOG   defaults to null
	std::ostream&	VERBOSE() {return verbose ? std::cout : strm_ignore;}
	std::ostream&	IGNORE() {return strm_ignore;}
	std::ostream&	MISSING_SEQ(){if (log_missing) return f_missing_log; return strm_ignore;}
	std::ostream&	BLAST_LOG(){if (log_blast_errors) return f_blast_log; return strm_ignore;}
	std::ostream&	CERR(){if (log_errors) return f_error_log; return std::cerr;}

	bool use_batch;
	unsigned batch;
	
	// for initializing this struct
	friend
	bool GetArguments(int argc, char* argv[], t_program_args& args);
	bool IsVerbose() const	{return verbose;}
	bool open_log_files(const std::string& PID);
private:
	std::string			blast_log_name;
	std::string			error_log_name;
	std::string			missing_log_name;
	bool				verbose;
	bool				log_errors;
	std::ofstream		f_error_log;
	bool				log_blast_errors;
	std::ofstream		f_blast_log;
	std::ostringstream 	strm_ignore;
	std::ofstream		f_missing_log;
	bool				log_missing;
};

bool GetArguments(int argc, char* argv[], t_program_args& args);
#endif //GETARG_H
